/** 
 * @ClassName: UserChargeService 
 * @Description:  充值
 * @author 832
 * @date 2016年10月11日 
 *  
 */
package com.fzrskj.cloud.free.user.service;

import com.fzrskj.cloud.free.consts.CConsts;
import com.fzrskj.cloud.free.core.enums.DicParamEnum;
import com.fzrskj.cloud.free.core.enums.PayWayEnum;
import com.fzrskj.cloud.free.core.enums.PayTypeEnum;
import com.fzrskj.cloud.free.core.tool.CDateTimeTool;
import com.fzrskj.cloud.free.core.tool.CJsonTool;
import com.fzrskj.cloud.free.core.tool.CSessionTool;
import com.fzrskj.cloud.free.core.tool.CStrTool;
import com.fzrskj.cloud.free.core.utils.CloudContextUtils;
import com.fzrskj.cloud.free.core.utils.DoubleUtil;
import com.fzrskj.cloud.free.dic.bean.DicParamItem;
import com.fzrskj.cloud.free.dic.bean.DicVipgrade;
import com.fzrskj.cloud.free.dic.utils.DicParamItemUtils;
import com.fzrskj.cloud.free.dic.utils.DicParamUtils;
import com.fzrskj.cloud.free.dic.utils.DicVipgradeUtils;
import com.fzrskj.cloud.free.user.bean.statistics.Statistics;
import com.fzrskj.cloud.free.user.tool.StatistisTool;
import com.fzrskj.cloud.free.user.utils.UserChargeUtils;
import com.fzrskj.cloud.free.user.utils.UserOrderUtils;
import com.fzrskj.cloud.free.user.bean.UserOrderView;
import com.fzrskj.cloud.free.user.bean.UserCharge;
import ms.core.consts.SysErr;
import ms.core.object.CObject;
import ms.core.tool.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserChargeService extends CObject{
	/**
	 * 消费记录查询
	 * @param req
	 * @param resp
	 * @param p={"startTime":"startTime","endDate":"endDate","orderId":"orderId","page":page,"pageSize":pageSize}
	 * @param sid
	 * @return
	 */
	public String getUserChargeListByPage(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		String userName = CSessionTool.getAccountCloud(sid);
		String startTime = CJsonTool.getStrValue(p,"startTime","");
		String endDate   = CJsonTool.getStrValue(p, "endDate", "");
		String orderId  = CJsonTool.getStrValue(p, "orderId", "");
		int page =CJsonTool.getIntValue(p, "page", 1);
		int pageSize =CJsonTool.getIntValue(p, "pageSize", CConsts.PAGE_SIZE);
		return getChargeList(userName, page, pageSize,startTime,endDate,orderId);
	}
	
	/**
	 * 所有会员充值记录查询(后台)
	 * @param req
	 * @param resp
	 * @param p={"userName":"userName";"startTime":"startTime","endDate":"endDate","orderId":"orderId","page":page,"pageSize":pageSize}
	 * @param sid
	 * @return
	 */
	public String getAllUserCharge(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		String userName = CJsonTool.getStrValue(p,"userName","");
		String startTime = CJsonTool.getStrValue(p,"startTime","");
		String endDate   = CJsonTool.getStrValue(p, "endDate", "");
		String orderId  = CJsonTool.getStrValue(p, "orderId", "");
		
		int page =CJsonTool.getIntValue(p, "page", 1);
		if (page<1) {
			page = 1;
		}
		int pageSize =CJsonTool.getIntValue(p, "pageSize", CConsts.PAGE_SIZE);
		if (pageSize<1) {
			pageSize = CConsts.PAGE_SIZE;
		}
		
		return getChargeList(userName, page, pageSize,startTime,endDate,orderId);
	}
	
	/**
	 * 查询会员充值记录，管理员和个人都转从这里查询
	 * @param userName
	 * @param page
	 * @param pageSize
	 * @param startTime
	 * @param endDate
	 * @param orderId
	 * @return
	 */
	public String getChargeList(String userName, int page, int pageSize, String startTime, String endDate, String orderId){
		//查询数据
		UserChargeUtils userChargeUtils = new UserChargeUtils();
		List<UserCharge> getUserCharge = userChargeUtils.getUserCharge(userName, page, pageSize,startTime,endDate,orderId);
		String code = userChargeUtils.getErrCode();
		//查询的list集合为空，并且输入的数据不为空
		if(getUserCharge.size()==0){
			String data = String.format("{\"getUserCharge\":%s}",getUserCharge);
			return XmlCodeParser.formatResultData(true, SysErr.CODE_SUCCESS, data);
			
		}
		int count = userChargeUtils.UserChargePage(userName, startTime, endDate, orderId);
		int pages= Math.round((count+pageSize-1)/pageSize);
		
		if (!code.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code);
		}
		DicParamItemUtils dicParamItemUtils = new DicParamItemUtils();
		//调用getListSysParamItemByEName方法查询数据
		List<DicParamItem> getListParamItemByType = dicParamItemUtils.getListSysParamItemByEName("payType", 0);
		String code2 = userChargeUtils.getErrCode();
		if (!code2.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code2);
		}
		List<DicParamItem> getListParamItemByStatus = dicParamItemUtils.getListSysParamItemByEName("rechargeStatus", 0);
		String code3 = userChargeUtils.getErrCode();
		if (!code3.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code3);
		}
		String data = String.format("{\"getUserCharge\":%s,\"getListParamItemByEName\":%s,\"getListParamItemByStatus\":%s}",CJsonTool.listBeanToJson(getUserCharge),CJsonTool.listBeanToJson(getListParamItemByType),CJsonTool.listBeanToJson(getListParamItemByStatus));
		return XmlCodeParser.formatResultPageData(code, page, pages, pageSize, count,data);
	}
	
	/**
	 * 账户充值
	 * @param req
	 * @param resp
	 * @param p={"amount":充值金额,"payType":支付方式,bankCode":银行编码}
	 * @param sid
	 * @return
	 */
	public String UserOnlineRecharge(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		int uid = CloudContextUtils.getSession().getUID();
		
		double amount = CJsonTool.getFloatValue(p,"amount",0f);
		//支付方式  1.支付宝, 2.盛付通
		String payType   = CJsonTool.getStrValue(p, "payType", null);
		//银行编码
		String bankCode   = CJsonTool.getStrValue(p, "bankCode", "");
		int rechargeType=0;
		if (!(amount > 0) || CStrTool.isBlankStr(payType)){
			return XmlCodeParser.formatResultTips(false, SysErr.SYS_PARAM_ERR);
		}
		
		//会员级别最低充值
		DicVipgradeUtils dvUtils=new DicVipgradeUtils();
		DicVipgrade ua=dvUtils.queryDicVipgradeByUid(uid);
		if(ua!=null){
			if(amount<ua.getMinCharge()){
				JSONObject result = new JSONObject();
				result.put("code", "-1"); 
				result.put("message", "当前会员级别最低充值"+ua.getMinCharge()+"元");			
				return XmlCodeParser.formatResultData(true, SysErr.CODE_SUCCESS,result.toString());
			}
		}
		
		UserChargeUtils userChargeUtils = new UserChargeUtils();
		JSONObject par = new JSONObject();
		par.put("amount", amount);
		par.put("uid", uid);
		par.put("uname", CSessionTool.getAccountCloud(sid));
		par.put("Ip", HttpTool.getRequestRemoteIp(req));
		par.put("email", CSessionTool.getAccountCloud(sid));
		
		//根据渠道设置发起充值的地方
		if(PayTypeEnum.SFT.equals(payType)){
			rechargeType = PayTypeEnum.SFT.getType();
			par.put("instCode", bankCode);
		} else if(PayTypeEnum.ALIPAY.equals(payType)) {
			rechargeType = PayTypeEnum.ALIPAY.getType();
		} else if (PayTypeEnum.WXPAY.equals(payType)) {
			rechargeType = PayTypeEnum.WXPAY.getType();
		}
		
		//查询数据
		String result=userChargeUtils.OnlineRecharge(rechargeType, par.toString());
		String code=SysErr.CODE_SUCCESS;
		if (!code.equals(SysErr.CODE_SUCCESS)){
			userChargeUtils.dispose();
			return XmlCodeParser.formatResultTips(false,code);
		}
		
		return XmlCodeParser.formatResultData(true, code,result);
	}
	
	/**
	 * 订单支付充值
	 * @param req
	 * @param resp
	 * @param p={"payType":支付方式,bankCode":银行编码,"orderId":产品订单号}
	 * @param sid
	 * @return
	 */
	public String OrderOnlineRecharge(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		int uid = CloudContextUtils.getSession().getUID();
		double amount=0;
		String payType   = CJsonTool.getStrValue(p, "payType", null);//支付方式  1.支付宝, 2.盛付通
		String bankCode   = CJsonTool.getStrValue(p, "bankCode", "");//银行编码
		String OrederId = CJsonTool.getStrValue(p, "orderId", null);
		UserChargeUtils userChargeUtils = new UserChargeUtils();
		JSONObject par = new JSONObject();
		par.put("uid", uid);
		par.put("uname", CSessionTool.getAccountCloud(sid));
		par.put("Ip", HttpTool.getRequestRemoteIp(req));
		par.put("email", CSessionTool.getAccountCloud(sid));
		if (!CStrTool.isBlankStr(OrederId)){
			//验证订单是否存在
			UserOrderUtils utils = new UserOrderUtils();
			String[] orders=OrederId.split(",");
			for(int i =0;i<orders.length;i++){
				UserOrderView userOrder = utils.getUserOrderView(orders[i]);
				if(userOrder==null){
					utils.dispose();
					return XmlCodeParser.formatResultTips(false, SysErr.SYS_PARAM_ERR);
				}
				amount+=userOrder.getPayAmount();
			}
			
			utils.dispose();
			par.put("orderId", OrederId);
		}
		
		//会员级别最低充值
		DicVipgradeUtils dvUtils=new DicVipgradeUtils();
		DicVipgrade ua=dvUtils.queryDicVipgradeByUid(uid);
		if(ua!=null){
			if(amount<ua.getMinCharge()){
				JSONObject result = new JSONObject();
				result.put("code", "-1"); 
				result.put("message", "当前会员级别最低消费"+ua.getMinCharge()+"元");			
				return XmlCodeParser.formatResultData(true, SysErr.CODE_SUCCESS,result.toString());
			}
		}
		
		int rechargeType=0;
		String rateValStr = "";
		//根据渠道设置发起充值的地方
		if (PayTypeEnum.SFT.equals(payType)) {
			rechargeType = PayTypeEnum.SFT.getType();
			par.put("instCode", bankCode);
			rateValStr = DicParamUtils.getParamValue(DicParamEnum.SFTPAY_RATE.getVal());
		} else if (PayTypeEnum.ALIPAY.equals(payType)) {
			rechargeType = PayTypeEnum.ALIPAY.getType();
			rateValStr = DicParamUtils.getParamValue(DicParamEnum.ALIPAY_RATE.getVal());
		} else if (PayTypeEnum.WXPAY.equals(payType)) {
			rechargeType = PayTypeEnum.WXPAY.getType();
			rateValStr = DicParamUtils.getParamValue(DicParamEnum.WECHAT_RATE.getVal());
		}
		if (!(amount > 0)){
			return XmlCodeParser.formatResultTips(false, SysErr.SYS_PARAM_ERR);
		}

		//费率计算.
		if (!StrTool.isBlankStr(rateValStr)) {
			Double rateVal = Double.valueOf(rateValStr);
			Double rate = DoubleUtil.sub(1.0, DoubleUtil.divide(rateVal, 100.0));
			amount = DoubleUtil.divide(amount, rate, 2);
		}

		par.put("amount", amount);
		//查询数据
		String result=userChargeUtils.OnlineRecharge(rechargeType, par.toString());
		String code=SysErr.CODE_SUCCESS;
		if (!code.equals(SysErr.CODE_SUCCESS)){
			userChargeUtils.dispose();
			return XmlCodeParser.formatResultTips(false,code);
		}
		
		return XmlCodeParser.formatResultData(true, code,result);
	}
	
	/**
	 * 订单号查询订单详情
	 * @param req
	 * @param resp
	 * @param p={"orderId":"orderId"}
	 * @param sid
	 * @return
	 */
	public String getChargeByOId(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		int uid = CloudContextUtils.getSession().getUID();
		String orderId = CJsonTool.getStrValue(p, "orderId", "");
		if (CStrTool.isBlankStr(orderId)){
			return XmlCodeParser.formatResultTips(false, SysErr.SYS_PARAM_ERR);
		}
		UserChargeUtils userChargeUtils = new UserChargeUtils();
		UserCharge UserCharge = userChargeUtils.getUserCharge(orderId);
		String code = userChargeUtils.getErrCode();
		if(!code.equals(SysErr.CODE_SUCCESS)){
			userChargeUtils.dispose();
			return XmlCodeParser.formatResultTips(false,code);
		}
		DicParamItemUtils dicParamItemUtils = new DicParamItemUtils();
		//调用getListSysParamItemByEName方法查询数据
		List<DicParamItem> getListParamItemByType = dicParamItemUtils.getListSysParamItemByEName("payType", 0);
		String code2 = userChargeUtils.getErrCode();
		if (!code2.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code2);
		}
		List<DicParamItem> getListParamItemByStatus = dicParamItemUtils.getListSysParamItemByEName("rechargeStatus", 0);
		String code3 = userChargeUtils.getErrCode();
		if (!code3.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code3);
		}
		String data = String.format("{\"getUserCharge\":%s,\"getListParamItemByEName\":%s,\"getListParamItemByStatus\":%s}",CJsonTool.beanToJson(UserCharge),CJsonTool.listBeanToJson(getListParamItemByType),CJsonTool.listBeanToJson(getListParamItemByStatus));
		return XmlCodeParser.formatResultData(true, SysErr.CODE_SUCCESS, data);
	}
	
	/**
	 * 手工处理充值订单
	 * @param req
	 * @param resp
	 * @param p={"orderId":"orderId","type":"type"}type=Y给用户入款，=N不给用户入款
	 * @param sid
	 * @return
	 */
	public String rechargeManual(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		String adminName = CSessionTool.getAccountCloud(sid);
		
		String orderId = CJsonTool.getStrValue(p, "orderId", "");
		String type = CJsonTool.getStrValue(p, "type", "");
		if (CStrTool.isBlankStr(orderId) || CStrTool.isBlankStr(type)){
			return XmlCodeParser.formatResultTips(false, SysErr.SYS_PARAM_ERR);
		}
		
		UserCharge UserCharge = new UserCharge();
		UserCharge.setOrderId(orderId);
		UserCharge.setStatus("Y");
		
		String remark="";
		if("Y".equals(type)) {
			remark = "手动入账并转已处理，操作员【" + adminName + "】";
		} else {
			remark = "未入账并转已处理，操作员【" + adminName + "】";
		}
		UserCharge.setRemark(remark);
		UserChargeUtils userChargeUtils = new UserChargeUtils();
		int ret = userChargeUtils.uptUsercharge(UserCharge);
		boolean success = (ret>0);
		String code = userChargeUtils.getErrCode();
		if(type.equals("Y") && success){
			String result = userChargeUtils.rechargeManual(orderId,sid);
			JSONObject obj = new JSONObject();
			obj= JSONObject.fromObject(result);
			if("0".equals(obj.getString("code").trim())) {
				return XmlCodeParser.formatResultTips(true, code);
			} else {
				return XmlCodeParser.formatResultTips(false, code);
			}
		}
		userChargeUtils.dispose();
		return XmlCodeParser.formatResultTips(success, code);
	}
	
	/**
	 * 充值统计
	 * @param req
	 * @param resp
	 * @param p={"bankCode":"充值方式","day":"查询天数","status":"充值订单的状态"} 默认结束时间为当天  //day 0和默认查询为当天   2表示查询今天和昨天的
	 * @param sid
	 * @return
	 */
	public String rechargeAmount(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		String status = CJsonTool.getStrValue(p, "status", "Y");
		String bankCode = CJsonTool.getStrValue(p, "bankCode", "");
		int day = CJsonTool.getIntValue(p, "day", 0);

		Map<String, Object> map = new HashMap<String, Object>();
		if (!CStrTool.isBlankStr(status)) {map.put("status", status);}
		if (!CStrTool.isBlankStr(bankCode)) {map.put("bankCode", bankCode);}
		if (day>=0) {
			map.put("start", CDateTimeTool.dateToDateString(CDateTimeTool.incDay(new Date(), -day)));
		}
		map.put("end", CDateTimeTool.dateToDateString(CDateTimeTool.incDay(new Date(), 1)));
		
		UserChargeUtils userChargeUtils = new UserChargeUtils();
		double ret = userChargeUtils.queryChargeAmount(map);
		String code = userChargeUtils.getErrCode();
		userChargeUtils.dispose();
		if (!code.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code);
		}
		if(ret>0){
			return XmlCodeParser.formatResultData(true, code,"\""+new java.text.DecimalFormat("#.00").format(ret)+"\"");
		}else{
			return XmlCodeParser.formatResultData(true, code,"\""+0+"\"");
		}
	}
	
	/**
	 * 会员查询充值统计
	 * @param req
	 * @param resp
	 * @param p={"paytype":"充值方式","startTime":"开始时间","endTime":"结束时间"} 
	 * @param sid
	 * @return
	 */
	public String UserRechargeCount(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		int uid = CloudContextUtils.getSession().getUID();
		
		String startTime = CJsonTool.getStrValue(p, "startTime", null);
		String endTime = CJsonTool.getStrValue(p, "endTime", null);

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userid", uid);
		if (!CStrTool.isBlankStr(startTime)) {map.put("start", startTime);}
		if (!CStrTool.isBlankStr(endTime)) {map.put("end", endTime);}
		UserChargeUtils userChargeUtils = new UserChargeUtils();
		List<Object[]> amount = userChargeUtils.queryChargeSum(map);
		String code = userChargeUtils.getErrCode();
		if (!code.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code);
		}
		if(amount.size()==0){
			userChargeUtils.dispose();
			String data = String.format("{\"total\":%s}",0);
			return XmlCodeParser.formatResultData(true, SysErr.CODE_SUCCESS, data);
		}
		
        double total=0;
		for(int i=0;i<amount.size();i++){
			total=total+Double.valueOf(amount.get(i)[1].toString());
		}
		
		return XmlCodeParser.formatResultData(true,code,String.format("{\"total\":%s}",total));
	}
	
	/**
	 * 管理员查询充值统计
	 * @param req
	 * @param resp
	 * @param p={"userId":"用户ID","paytype":"充值方式","startTime":"开始时间","endTime":"结束时间"} 
	 * @param sid
	 * @return
	 */
	public String AdminRechargeCount(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		String startTime = CJsonTool.getStrValue(p, "startTime", "");
		String endTime = CJsonTool.getStrValue(p, "endTime", "");
		String userName = CJsonTool.getStrValue(p, "userName", "");

		Map<String, Object> map = new HashMap<String, Object>();
		if (!CStrTool.isBlankStr(startTime)) {map.put("start", startTime);}
		if (!CStrTool.isBlankStr(endTime)) {map.put("end", endTime);}
		if (!CStrTool.isBlankStr(userName)) {map.put("userName", userName);}
		
		UserChargeUtils userChargeUtils = new UserChargeUtils();
		List<Object[]> amount = userChargeUtils.queryChargeSum(map);
		String code = userChargeUtils.getErrCode();
		if (!code.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code);
		}
		if(amount.size()==0){
			userChargeUtils.dispose();
			String data = String.format("{\"item\":%s}",amount);
			return XmlCodeParser.formatResultData(true, SysErr.CODE_SUCCESS, data);
		}
		
		DicParamItemUtils dicParamItemUtils = new DicParamItemUtils();
		List<DicParamItem> paramItemList = dicParamItemUtils.getListSysParamItemByEName("payType", 0);
		code = dicParamItemUtils.getErrCode();
		if (!code.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, code);
		}
		
	    double total=0;
		JSONArray json=new JSONArray();
		for(int i=0;i<amount.size();i++){
			Object[] obj2=amount.get(i);
			String jstr="{}";
			jstr=CJsonTool.addNode(jstr, "paytype", obj2[0]);
			jstr=CJsonTool.addNode(jstr, "sum", obj2[1]);
			total+=Double.parseDouble(obj2[1].toString());
			json.add(jstr);
		}
		
		String data = String.format("{\"item\":%s,\"paramItemList\":%s,\"total\":%s}",json.toString(),CJsonTool.listBeanToJson(paramItemList),total);
		return XmlCodeParser.formatResultData(true, code,data);
	}
	
	/**
	 * 管理员查询充值统计
	 * @param req
	 * @param resp
	 * @param p
	 * @param sid
	 * @return
	 */
	public String getPayChannl(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		String paytype=getTrueChannl();
		if (paytype.equals("-1")) {
			return XmlCodeParser.formatResultTips(false, SysErr.SYS_DATA_NOT_FOUND);
		}

		com.alibaba.fastjson.JSONObject rate = new com.alibaba.fastjson.JSONObject();
		if (paytype.indexOf("alipay") > -1) {
			String alipayRate = DicParamUtils.getParamValue(DicParamEnum.ALIPAY_RATE.getVal());
			if (StrTool.isBlankStr(alipayRate)) {
				alipayRate = "0";
			}
			rate.put("alipayrate", alipayRate);
		}
		if (paytype.indexOf("sftpay") > -1) {
			String sftpayRate = DicParamUtils.getParamValue(DicParamEnum.SFTPAY_RATE.getVal());
			if (StrTool.isBlankStr(sftpayRate)) {
				sftpayRate = "0";
			}
			rate.put("sftpayrate", sftpayRate);
		}
		
		String data = String.format("{\"channl\":\"%s\",\"rate\":%s}",paytype, com.alibaba.fastjson.JSONObject.toJSON(rate));
		return XmlCodeParser.formatResultData(true, SysErr.CODE_SUCCESS,data);
	}

	/**
	 * 按时间段统计符合充值金额
	 * @param req
	 * @param resp
	 * @param p={"timeType":时间类型  W本周 M 本月 }
	 * @param sid
	 * @return
	 * add wzj by 2018/12/12
	 */
	public String queryRechargeCountByDatetime(HttpServletRequest req, HttpServletResponse resp, String p, String sid){
		String timeType = JsonTool.getStrValue(p,"timeType","W");
		String startTime = JsonTool.getStrValue(p,"startTime",null);
		if (StrTool.isBlankStr(timeType)) {
			return XmlCodeParser.formatResultTips(false, SysErr.SYS_PARAM_ERR);
		}

		if("W".equals(timeType)){ //本周
			startTime = DateTimeTool.dateToDateString(DateTimeTool.incDay(new Date(), -7));
		} else if("M".equals(timeType)){ //本月
			startTime = DateTimeTool.dateToDateString(DateTimeTool.incMonth(new Date(), -1));
		} else {
			return XmlCodeParser.formatResultTips(false, SysErr.SYS_PARAM_ERR);
		}

		String endTime = DateTimeTool.dateToDateString(new Date());

		UserChargeUtils obj = new UserChargeUtils();
		Map<String, Object> cdt = new HashMap<String, Object>();
		if (!StrTool.isBlankStr(startTime)) {
			cdt.put("startTime", startTime);
		}

		List<Statistics> rets = obj.queryOrderCount(cdt, "D");
		String err = obj.getErrCode();
		obj.dispose();
		if (!err.equals(SysErr.CODE_SUCCESS)) {
			return XmlCodeParser.formatResultTips(false, err);
		}

		return XmlCodeParser.formatResultData(true, err, StatistisTool.getLineDate(rets, startTime, endTime));
	}
	
	private String configFile="/config/paychannl.properties";
	private PropTool cfg =null;
	
	//获取已配置齐全的接口
	private  String getTrueChannl(){
		String Channl="";
		cfg = new PropTool(configFile);
		String paychannl=cfg.getValue("paychannl", "").trim();
		if(!CStrTool.isBlankStr(paychannl)){
			String[] channlarr=paychannl.split(",");
			for(String str:channlarr){
				if(channlcheck(str)){
					Channl+=str+",";
				}
			}
		}
		
		//去除最后的 ‘,’
		if(Channl.length()>=1){
			Channl=Channl.substring(0, Channl.length()-1);
		}
		
		if(CStrTool.isBlankStr(Channl)){
			return "-1";
		}
		
		return Channl;
	}
	
	//支付接口配置判断
	private boolean channlcheck(String channl){
		if(channl.equals("alipay")){
			if (sysalipaycheck(channl)) {
				return false;
			}
		}else{
			String way = DicParamUtils.getParamValue(PayWayEnum.SFT.getKey());
			Integer agentId = CloudContextUtils.getAgentId();
			if ("99".equals(way)) {
				agentId = DicParamUtils.getLastSelfPayParent(PayWayEnum.SFT.getKey(), agentId);
			}

			String parameters=cfg.getValue(channl, "").trim();
			String[] parameterarr=parameters.split(",");
			for (String par : parameterarr) {
				if (sysconfigcheck(par, agentId)) {
					return false;
				}
			}
		}
		return true;
	}

	//确认接口参数是否配置齐全
	private boolean sysconfigcheck(String str, Integer agentId){
		return CStrTool.isBlankStr( DicParamUtils.getParamValue(str, agentId));
	}
	
	//支付宝特殊配置
	private boolean sysalipaycheck(String channl){
		String parameters=cfg.getValue(channl, "").trim();
		String[] parameterarr=parameters.split(",");
		String way=DicParamUtils.getParamValue(parameterarr[0]);
		int max=5;
		if(way.equals("2")){
			max=3;
		}

		//使用上级收款账户
		Integer agentId = CloudContextUtils.getAgentId();
		if ("99".equals(way)) {
			agentId = DicParamUtils.getLastSelfPayParent(parameterarr[0], agentId);
		}

		for(int k = 1;k<max;k++){
			if(CStrTool.isBlankStr( DicParamUtils.getParamValue(parameterarr[k], agentId))){
				return true;
			}
		}
		return false;
	}
}
